//
//  YTTipsShowView.m
//  YuTangz
//
//  Created by 葛悦彣 on 2024/8/1.
//

#import "YTTipsShowView.h"

@interface YTTipsShowView ()

@property (nonatomic ,strong) UIView * makeView;
@property (nonatomic ,strong) GYWclickBlock rightblock;
@property (nonatomic ,strong) GYWclickBlock leftblock;
@property (nonatomic ,strong) UIView * contentView;

@property (nonatomic ,assign) CGFloat viewH;

@end

@implementation YTTipsShowView
///单行提示
+ (instancetype)showviewWithTips:(NSString *)tips andRightBlock:(void(^)(void))rightblock{
    
    return [self showviewWithTips:tips andLeftTitle:@"取消" andLeftBlock:nil andRightBlock:rightblock];
}

+ (instancetype)showviewWithview: (void(^)(UIView * view))block andviewHight:(CGFloat)viewHight andLeftTitle:(NSString *)lefttitle andRightTitle:(NSString *)righttitle andLeftBlock:(void(^)(void))leftblock andRightBlock:(void(^)(void))rightblock{
    YTTipsShowView * view = [YTTipsShowView new];
    view.leftblock = leftblock;
    view.rightblock = rightblock;
    [[DTKTool getCurrentVC].view addSubview:view];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.viewH = viewHight;
    UIView * makeView = [UIView new];
    view.makeView = makeView;
    makeView.backgroundColor = UIColor.whiteColor;
    makeView.frame = CGRectMake(kwt(37.5), (SCREEN_HEIGHT - view.viewH)/2, SCREEN_WIDTH - kwt(75), view.viewH);
    [view addSubview:makeView];
    [DTKTool YJ:kwt(15) andView:makeView];
    
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    
    UIView * contentView = [UIView new];
    view.contentView = contentView;
    [makeView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.bottom.offset(kwt(-70));
    }];
    block(contentView);
 
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = UIColor.whiteColor;
    if(lefttitle.length > 0){
        [qxbtn setTitle:lefttitle forState:UIControlStateNormal];
    } else {
        [qxbtn setTitle:@"暂不" forState:UIControlStateNormal];
    }
    [qxbtn setTitleColor:KcolorHex(@"#1E2425") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(16);
    [DTKTool YJBK:kwt(24) andView:qxbtn andWidth:0.5 andColor:KcolorHex(@"#C9C9C9")];
    [qxbtn addTarget:view action:@selector(leftBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [makeView addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(120));
        make.left.offset(kwt(24));
        make.bottom.offset(kwt(-23));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(120), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#0E66FF") endColor:KcolorHex(@"#73A5FB")];
    [qrbtn setTitle:righttitle forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(16);
    [DTKTool YJ:kwt(24) andView:qrbtn];
    [qrbtn addTarget:view action:@selector(rightbtnclick) forControlEvents:UIControlEventTouchUpInside];
    [makeView addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(120));
        make.right.offset(kwt(-24));
        make.bottom.offset(kwt(-20));
    }];
    
    [view show];
    
    return  view;
    
}
+ (instancetype)showviewWithTips:(NSString *)tips andLeftTitle:(NSString *)lefttitle andLeftBlock:(void(^)(void))leftblock andRightBlock:(void(^)(void))rightblock{

    YTTipsShowView * view = [YTTipsShowView new];
    view.leftblock = leftblock;
    view.rightblock = rightblock;
    [[DTKTool getCurrentVC].view addSubview:view];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.viewH = kwt(165);
    UIView * makeView = [UIView new];
    view.makeView = makeView;
    makeView.backgroundColor = UIColor.whiteColor;
    makeView.frame = CGRectMake(kwt(37.5), (SCREEN_HEIGHT - view.viewH)/2, SCREEN_WIDTH - kwt(75), view.viewH);
    [view addSubview:makeView];
    [DTKTool YJ:kwt(15) andView:makeView];
    
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    
    UILabel * titlab = [DTKTool labelWithText:tips andFont:kCFont(18) andTextColor:KcolorHex(@"#1E2425")];
    [makeView addSubview:titlab];
    titlab.numberOfLines = 2;
    titlab.textAlignment = NSTextAlignmentCenter;
    [titlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(35));
        make.width.offset(kwt(245));
    }];
    
 
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = UIColor.whiteColor;
    if(lefttitle.length > 0){
        [qxbtn setTitle:lefttitle forState:UIControlStateNormal];
    } else {
        [qxbtn setTitle:@"暂不" forState:UIControlStateNormal];
    }
    [qxbtn setTitleColor:KcolorHex(@"#1E2425") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(16);
    [DTKTool YJBK:kwt(24) andView:qxbtn andWidth:0.5 andColor:KcolorHex(@"#C9C9C9")];
    [qxbtn addTarget:view action:@selector(leftBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [makeView addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(120));
        make.left.offset(kwt(24));
        make.bottom.offset(kwt(-23));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(120), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#0E66FF") endColor:KcolorHex(@"#73A5FB")];
    [qrbtn setTitle:@"确定" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(16);
    [DTKTool YJ:kwt(24) andView:qrbtn];
    [qrbtn addTarget:view action:@selector(rightbtnclick) forControlEvents:UIControlEventTouchUpInside];
    [makeView addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(120));
        make.right.offset(kwt(-24));
        make.bottom.offset(kwt(-20));
    }];
    
    [view show];
    
    return  view;
    
    
}

- (void)leftBtnclick{
    if(self.leftblock){
        self.leftblock();
        [self dismiss];
    } else {
        [self dismiss];
    }
}
- (void)rightbtnclick{
    if(self.rightblock){
        self.rightblock();
    }
    [self dismiss];
}


- (void)show{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(kwt(37.5), (SCREEN_HEIGHT - self.viewH)/2, SCREEN_WIDTH - kwt(75), self.viewH);
    }];
}
- (void)noclick{}
- (void)dismiss{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(kwt(37.5), SCREEN_HEIGHT, SCREEN_WIDTH - kwt(75),self.viewH);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}


@end
